import React from 'react';
import { useState } from 'react'
import { useHistory } from 'react-router-dom'
const News = () => {
    const [newslist, setnewsListFn] = useState([{
        id: 1,
        name: '习近平和来华的美国国务卿布林肯会面'
    }, {
        id: 2,
        name: '中超要求贵州村超停办整顿'
    }, {
        id: 3,
        name: '年轻人该不该买房'
    }])

    // 创建history 对象
    // his 就相当于类组件中的this.props.history
    const his = useHistory()
    // console.log('his', his);
    return (
        <div>
            <p>新闻组件</p>
            <ul>
                {
                    newslist.map(item => <li key={item.id} onClick={() => {
                        // his.push('/detail?id=' + item.id)
                        his.push('/detail/' + item.id)
                    }}>{item.name}</li>)
                }
            </ul>
        </div>
    );
}

export default News;
